import axios from 'axios'

axios.defaults.baseURL = 'http://localhost:8080/api/private/v1/'

export function login(userinfo) {
  return axios.get('login', {
    params: userinfo,
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

export function logout(username) {
  return axios.put(`/logout/${username}`)
}

export function getRoom(id) {
  return axios.get(`search_room/${id}`)
}

export function createRoom(userinfo) {
  return axios.post('create_room', userinfo, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

export function getRoomPlayers(roomId) {
  return axios.get('room_players', {
    params: {
      id: roomId,
    },
  })
}

export function joinRoom(roomId, playerInfo) {
  return axios.post(`link_to_room/${roomId}`, playerInfo, {
    headers: {
      'Content-Type': 'application/json',
    },
  })
}

export function startGame(roomId) {
  return axios.post(
    `start/${roomId}`,
    {},
    {
      headers: {
        'Content-Type': 'application/json',
      },
    }
  )
}

export function getRoomMessage(roomId) {
  return axios.get(`message/${roomId}`)
}
